package com.haois.mp.wechat.server;

import com.haois.mp.database.module.basic.util.SpringContextHolder;
import com.haois.mp.database.module.common.daomain.Parameter;
import com.haois.mp.database.util.ReflectUtil;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 描述
 *
 * @author RuiHaoZ on GuangZhou
 * @date 2018/8/4 10:36
 */
@Service
public class MoreInfoController {

    public String transferChoice(WxMpXmlMessage wxMpXmlMessage, Parameter parameter) {
        AbstractMoreInfoServer moreInfoServer = null;
        try {
            //"mp.wechat.handler.search." +
            //Class<AbstractMoreInfoServer> classZ = (Class<AbstractMoreInfoServer>) Class.forName(className);
            //moreInfoServer = classZ.newInstance();
            String className = ReflectUtil.getClassName(parameter.getMethod());
            moreInfoServer = SpringContextHolder.getBean(className);
            if (moreInfoServer != null) {
                String reply = moreInfoServer.execute(wxMpXmlMessage);
                return StringUtils.isEmpty(reply) ? parameter.getReply() : reply;
            } else {
                return "数据库配置有误，请联系管理员";
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "系统出现异常，请稍候再试";
        }
    }
}
